package com.web.article;

import com.bean.Article;
import com.service.ArticleService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

public class FindArticleByIdServlet extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int id=Integer.valueOf(req.getParameter("id"));
        ArticleService service=new ArticleService();


        Article a= null;
        try {
            a = service.find(id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        req.getSession().setAttribute("article",a);

        req.getRequestDispatcher("/admin/article/ArticleSingle.jsp").forward(req,resp);


       // resp.sendRedirect("/dispay.jsp");

    }
}
